package com.hotline.communication.service.impl;


import com.hotline.communication.mapper.ParamMapper;
import com.hotline.communication.mapper.ParamSetMapper;
import com.hotline.communication.entity.Param;
import com.hotline.communication.entity.ParamSet;
import com.hotline.communication.service.ParamSetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service
@Slf4j
public class ParamSetServiceImpl implements ParamSetService {

    @Resource
    private ParamSetMapper paramSetMapper;

    @Resource
    private ParamMapper paramMapper;

    @Override
    public String getParamValue(String paramId,String orgId) {

        String paramValue = null;

        //取机构设置值
        ParamSet paramSetDTO = paramSetMapper.selectById(paramId,orgId);
        if(Objects.nonNull(paramSetDTO)){
            paramValue = paramSetDTO.getParamValue();
            return paramValue;
        }

        //未取到设置值，取默认值
        Param paramDTO = paramMapper.selectById(paramId);
        if(Objects.nonNull(paramDTO)){
            paramValue = paramDTO.getDefaultValue();
        }
        return paramValue;
    }

}
